home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / adatimer.zip / TIMEL1.ADA < prev    next >
Text File  |  1990-06-07  |  3KB  |  93 lines

  1. -- Listing 1. Package specification for a polled timer.
  2.  
  3. generic
  4.   type Seconds is private;
  5.   with function Dimensionless
  6.     (T : Seconds) return float
  7.     is <>;
  8.   with function Type_Convert
  9.     (F : float) return Seconds
  10.     is <>;
  11. package POLLED_TIMER is
  12.  
  13.   INVALID_PERIOD : exception;
  14.     -- The requested period is too long
  15.     -- or two short. Use the Max_Period
  16.     -- and/or Single_Tick function to
  17.     -- find out what is wrong.
  18.  
  19.   type Modes is (SINGLE, REPEATED);
  20.     -- Program the timer to expire once,
  21.     -- then stop (SINGLE), or program it
  22.     -- to start another timing cycle as
  23.     -- soon as the first one finishes
  24.     -- (REPEATED).
  25.  
  26.   -- Call the following procedure once
  27.   -- to initially configure the timer.
  28.   -- It should not be called again,
  29.   -- unless you want to change the
  30.   -- PERIOD or the MODE.
  31.  
  32.   procedure Set(PERIOD : Seconds;
  33.                 MODE   : Modes);
  34.     -- May raise INVALID_PERIOD from the
  35.     -- TIMER_EXCEPTION package. If so,
  36.     -- use the two functions at the end
  37.     -- of this package to find out what
  38.     -- went wrong.
  39.  
  40.   procedure Start;
  41.     -- Starts the timer running in the
  42.     -- MODE determined by Set.
  43.  
  44.   procedure Restart;
  45.     -- Reloads the counter with the
  46.     -- desired time delay and starts
  47.     -- the counter again.
  48.  
  49.   function Has_Expired return boolean;
  50.     -- Poll this function to see if the
  51.     -- time delay has expired yet.
  52.  
  53.   procedure Stop;
  54.     -- If the MODE is REPEATED, you
  55.     -- should use this procedure at the
  56.     -- end of the program to turn off
  57.     -- the timer. (Otherwise it will
  58.     -- keep running after the program is
  59.     -- finished.) You need not use it in
  60.     -- SINGLE mode because the timer
  61.     -- will stop automatically as soon
  62.     -- as it expires.
  63.  
  64.     -- You can also use this procedure,
  65.     -- in conjuction with Start, to
  66.     -- simulate a stopwatch.
  67.  
  68.   function Time_Used return Seconds;
  69.     -- Tells you how many seconds have
  70.     -- gone by since you started the
  71.     -- timer.  It does NOT stop the
  72.     -- timer.
  73.  
  74.   function Time_Left return Seconds;
  75.     -- Tells you how many seconds until
  76.     -- the time delay will expire.  It
  77.     -- does NOT stop the timer.
  78.  
  79.   -- The following two functions tell
  80.   -- the limitations of the underlying
  81.   -- physical timer. They can be called
  82.   -- before setting the period to make
  83.   -- sure the timer can support the
  84.   -- desired time resolution, or they
  85.   -- can be called after Set raises
  86.   -- TIMER_EXCEPTION.INVALID_PERIOD to
  87.   -- find out what went wrong.
  88.  
  89.   function Max_Period return Seconds;
  90.   function Single_Tick return Seconds;
  91.  
  92. end POLLED_TIMER;
  93.